//
//  FWBCollectionViewCell.m
//  CustomCollectionViewDemo
//
//  Created by apple on 2017/5/22.
//  Copyright © 2017年 FWB. All rights reserved.
//

#import "FWBCollectionViewCell.h"

@interface FWBCollectionViewCell ()

/** 图片 */
@property (nonatomic,strong) UIImageView * imageView;
/** 标题 */
@property (nonatomic,strong) UILabel * titleLbl;

/** 图片数据 */
@property (nonatomic,strong) NSArray *arrimg;
/** 视频播放按钮*/
@property (nonatomic,strong) UIButton *btnplayer;

/** 头像*/
@property (nonatomic,strong) UIImageView *headImage;
/** 时间*/
@property (nonatomic, strong) UILabel *timeLab;
@end

@implementation FWBCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.imageView = [[UIImageView alloc] init];
        _imageView.clipsToBounds = YES;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_imageView];
        
        self.titleLbl = [UILabel new];
        _titleLbl.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        _titleLbl.font = [UIFont systemFontOfSize:15];
        _titleLbl.numberOfLines = 0;
        
        [self.contentView addSubview:_titleLbl];
        
        self.layer.cornerRadius = 5;
        self.clipsToBounds = YES;
        
        _btnplayer = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnplayer addTarget:self action:@selector(btnplayer) forControlEvents:UIControlEventTouchUpInside];
        [_btnplayer setImage:[UIImage imageNamed:@"stranger_trends_play"] forState:UIControlStateNormal];
        _btnplayer.hidden = YES;
        [_imageView addSubview:_btnplayer];
        
        self.headImage = [UIImageView new];
        _headImage.clipsToBounds = YES;
        _headImage.contentMode = UIViewContentModeScaleAspectFill;
        _headImage.layer.cornerRadius = 20;
        [self.contentView addSubview:_headImage];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        self.timeLab.font = [UIFont systemFontOfSize:12];
        self.timeLab.numberOfLines = 0;
        
        [self.contentView addSubview:self.timeLab ];

        
        
    }
    return self;
}
-(void)setModel:(Active *)model{
    _model = model;
    
    if (_model.img.length) {
        _arrimg = [[NSArray alloc] init];
        
        _arrimg = [_model.img componentsSeparatedByString:@","];
    }
    
    self.imageView.hidden = (!_model.img);
    self.titleLbl.hidden = (!_model.content);
    
    
    _imageView.frame = CGRectMake(0, 0, self.frame.size.width, cellImageH*SCREEN_WIDTH_RATIO47);
    _btnplayer.frame = CGRectMake(_imageView.centerX-15, _imageView.centerY-15, 30, 30);
    
    if (_model.video.length>0) {
        _btnplayer.hidden = NO;
    }else{
        _btnplayer.hidden = YES;

    }
    
    if (_imageView.hidden == YES) {
        _titleLbl.frame = CGRectMake(15, 30, self.frame.size.width-40, (cellTextH-10-35-20)*SCREEN_WIDTH_RATIO47);
        _headImage.frame = CGRectMake(15, self.contentView.bottom-44, 40, 40);
        _timeLab.frame = CGRectMake(_headImage.right+50, self.contentView.bottom-34, 80, 24);

    }else{
        _titleLbl.frame = CGRectMake(15, _imageView.frame.size.height+30, self.frame.size.width-40, (cellTextH-10-35-15)*SCREEN_WIDTH_RATIO47);
        _headImage.frame = CGRectMake(15, self.contentView.bottom-44, 40, 40);
        _timeLab.frame = CGRectMake(_headImage.right+50, self.contentView.bottom-34, 80, 24);

    }
    
    
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(_arrimg[0])] placeholderImage:[UIImage imageNamed:@"llustration"]];
    self.titleLbl.text = _model.content;
    self.timeLab.text = _model.createTime;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(_model.photo)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    

}


@end
